package com.action.photo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.photo.PhotoType;
import com.business.photo.PhotoTypeBus;
import com.config.SystemGlobals;

public class AddPhotoType extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
		String phototypeName = request.getParameter("phototypename");
		String phototypeMemo = request.getParameter("phtotypememo");
		String username = request.getParameter("username");
		PhotoType pt = new PhotoType();
		pt.setPhototypeMemo(phototypeMemo);
		pt.setPhototypeName(phototypeName);
		pt.setUsername(username);
		PhotoTypeBus ptb = new PhotoTypeBus();
		String action = request.getParameter("action");
		if (action.equals("add")) {
			ptb.add(pt);
			out
					.print("<script>alert(\"添加相册成功\");window.location=\"user/addphoto.jsp\";</script>");
			out.close();
		}
		if (action.equals("update")) {
			String typeId = request.getParameter("id");
			ptb.update(pt, typeId);
			RequestDispatcher rd = request.getRequestDispatcher("user/photolist.jsp");
			rd.forward(request, response);
		}
	}

}
